﻿Imports MySql.Data.MySqlClient
Public Class form_rekap_sopir
    Inherits DevExpress.XtraEditors.XtraForm
    Private Sub form_rekap_sopir_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DS_tugas_sopir.tugas' table. You can move, or remove it, as needed.
        Me.TugasTableAdapter1.Fill(Me.DS_tugas_sopir.tugas)
        DevExpress.Skins.SkinManager.EnableFormSkins()
        DevExpress.UserSkins.BonusSkins.Register()
        DevExpress.UserSkins.OfficeSkins.Register()
        Me.LookAndFeel.SkinName = "Office 2010 Blue"
        DefaultLookAndFeel1.LookAndFeel.SkinName = "Office 2010 Blue"
        Me.TugasTableAdapter.Fill(Me.DS_t01_tugas.tugas)
    End Sub

    Private Sub TugasDataGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles TugasDataGridView.CellClick
        ID_SOPIR.Text = TugasDataGridView.Rows(e.RowIndex).Cells(0).Value.ToString()
        TGL_AWAL.Text = TugasDataGridView.Rows(e.RowIndex).Cells(3).Value.ToString()
        TGL_AKHIR.Text = TugasDataGridView.Rows(e.RowIndex).Cells(4).Value.ToString()
        Dim myConnString As String
        myConnString = "server=localhost;User Id=root;password=;Persist Security Info=True;database=db_petruk_new"
        Dim ds As New DataSet
        Dim dsconn As New MySqlConnection(myConnString)
        Dim dsDa As New MySqlDataAdapter
        Dim strsql As String = "SELECT tugas.TGL_AWAL,tugas.TGL_AKHIR,master_sopir.NAMA,master_truk.PLAT_NOMOR,master_titik.NAMA_TPS FROM tugas JOIN master_sopir ON master_sopir.ID_SOPIR=tugas.ID_SOPIR JOIN tugas_tps ON tugas_tps.ID_TUGAS=tugas.ID_TUGAS JOIN master_titik ON master_titik.ID_TITIK=tugas_tps.ID_TITIK JOIN master_truk ON master_truk.ID_TRUK = master_sopir.ID_TRUK WHERE TGL_AWAL >= '" & Me.TGL_AWAL.Text & "' AND TGL_AKHIR <= '" & Me.TGL_AKHIR.Text & "' AND tugas.ID_SOPIR = " & Me.ID_SOPIR.Text & ""
        Try
            dsconn.Open()
            dsDa.SelectCommand = New MySqlCommand(strsql, dsconn)
            dsDa.Fill(ds)
            ds.WriteXml(CurDir() & "/rekap_sopir.xml", XmlWriteMode.WriteSchema)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub

    Private Sub TugasDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles TugasDataGridView.CellContentClick
        On Error Resume Next
        Select Case e.ColumnIndex
            Case 6
                report_sopir.Show()
        End Select
    End Sub
End Class